package com.youka.bussiness.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import com.youka.bussiness.common.bean.RestResp;
import com.youka.bussiness.common.base.BaseEntity;
import com.youka.bussiness.common.base.BaseController;
import com.youka.bussiness.service.TestdService;
import com.youka.bussiness.service.req.TestdReqDto;
import com.youka.bussiness.service.req.TestdUpdateDto;
import com.youka.bussiness.service.req.TestdPageDto;
import com.youka.bussiness.service.res.TestdDto;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.ArrayList;
import java.util.List;


import java.util.Map;

/**
 *  Controller
 *
 * @author lfc
 * @date 2024-05-07 21:56:41
 */
@Api(tags = "web-测试")
@RestController()
@RequestMapping("/web/Testd")
public class TestdController extends BaseController{

    @Autowired
    private TestdService testdService;

    /**
     * 查询详情
     */
    @ApiOperation(value = "获取详情")
    @PostMapping(value = "/single")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = TestdDto.class)
    })
    public RestResp findTestdById(@RequestBody BaseEntity entity) {
        TestdDto dto = testdService.selectById(entity.getId());
        return success(dto);
    }

    /**
     * 查询集合
     */
    @ApiOperation(value = "查询集合")
    @PostMapping("/list")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = TestdDto.class)
    })
    public RestResp listTestd(@RequestBody TestdReqDto testdPageDto) {
        List<TestdDto> list = testdService.selectByList(testdPageDto);
        return success().toAdminTree(list);
    }

    /**
     * 查询分页
     */
    @ApiOperation(value = "查询分页")
    @PostMapping("/page")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = TestdDto.class)
    })
    public RestResp pageTestd(@RequestBody TestdPageDto testdPageDto) {
        IPage<TestdDto> page = testdService.selectByPage(testdPageDto);
        return success().toAdminPage(page);
    }

    /**
     * 新增
     */
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = RestResp.class)
    })
    public RestResp addTestd(@RequestBody TestdReqDto testdReqDto) {
        testdService.insert(testdReqDto);
        return success();
    }

    /**
     * 编辑
     */
    @ApiOperation(value = "编辑")
    @PostMapping("/update")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = RestResp.class)
    })
    public RestResp updateTestd(@RequestBody TestdUpdateDto testdReqDto) {
        testdService.update(testdReqDto);
        return success();
    }

    /**
     * 删除主键
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询详情", response = RestResp.class)
    })
    public RestResp delete(@RequestBody BaseEntity entity) {
        testdService.deleteById(entity.getId());
        return success();
    }

}
